<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数值扩散</title>
</head>

<body>
    <script>
        //0. Number.EPSILON 是 JavaScript表示的最小精度，主要用来做浮点数的运算
        //EPSILON 属性的值接近于 2.22044604925031308084726333361816E-16
        console.log(0.1 + 0.2 === 0.3); //0.3000000000000000004
        function equal(a, b) {
            //如果a,b相减的绝对值小于Number.EPSILON,则表示两者相等
            if (Math.abs(a - b) < Number.EPSILON) {
                return true;
            } else {
                return false;
            }
        }

        console.log(equal(0.1 + 0.2, 0.3));

        //1.二进制和八进制
        let b = 0b1010;  //二进制ob

        let o = 0o777; //八进制0o

        let d = 100; //十进制

        let x = 0xff;  //十六进制0x


        //2.Number.isFinite 检测一个数值是否为有限数
        console.log(Number.isFinite(100)); //是有限数true
        console.log(Number.isFinite(100 / 0)); //不是有限数false
        console.log(Number.isFinite(Infinity)); //不是有限数false



        //3.Number.isNaN 检测一个数值是否为NaN
        console.log(Number.isNaN(123));

        //4.Number.parseInt Number.parseFloat字符串转整数
        console.log(Number.parseInt('52113112688888888888888love')); //它会只截断数字部分
        console.log(Number.parseFloat('3.1415926神奇'));  //同样也会截取

        //5.Number.isInteger判读一个数是否为整数
        console.log(Number.isInteger(5));
        console.log(Number.isInteger(2.5));

        //6.Math.trunc将数字的小数部分抹掉
        console.log(Math.trunc(3.5));

        //7.Math.sign 判读一个数到底为正数 负数 还是零
        console.log(Math.sign(100));  //1
        console.log(Math.sign(0)); //0
        console.log(Math.sign(-1)); //-1
    </script>
</body>

</html>